<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/1
 * Time: 10:34
 */
namespace core;
class user
{
    public $userName;
    public $password;
    public $type;

    /**
     * user constructor.
     * @param $userName
     * @param $password
     * 类初始化
     */
    public function __construct($userName,$password,$type)
    {
        //初始化，传入用户输入的账号和密码
        $this->userName=$userName;
        $this->password=$password;
        $this->type = $type;
        echo '传值初始化成功';
        echo '<br>';
    }




    /**
     * 类方法注册
     */
    public function register(){
        //判定注册账户是否存在
        $keyValue = $this->md5_rand();
        echo '账号注册成功;'.'账号为：'.$this->userName.'<br>'.'密码为：'.$this->password;
        echo '<br>';
        echo '该账户的唯一标识码：'.$keyValue;
    }

    //注册生成唯一串码
    private function md5_rand(){
        $rand_num = rand(100000,999999);
        $keyValue = md5($rand_num);
        return $keyValue;
    }

    /**
     * 类方法登录
     */
    public function login(){
        //判定账号密码是否正确

        //普通用户_管理员
        echo '账号登录成功';
        echo '<br>';
    }

    /**
     * 删除清空数据
     */
    public function __destruct()
    {
        // TODO: Implement __destruct() method.
        echo '<br>';
        echo '清除对象数据';
    }

    public static function getType(){
        return [
            'admin'=>'0',
            'ordinary_user'=>'1'
        ];
    }
}